{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "561acdb8",
   "metadata": {},
   "outputs": [
    {
     "ename": "ImportError",
     "evalue": "cannot import name 'quotes_historical_yahoo_ohlc' from 'mpl_finance' (c:\\vnstudio\\lib\\site-packages\\mpl_finance.py)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_9592/2750216739.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[1;31m# old version ablish import matplotlib.finance as mpf\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[1;31m#from mpl_finance import mpf\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mmpl_finance\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mcandlestick_ohlc\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mquotes_historical_yahoo_ohlc\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mImportError\u001b[0m: cannot import name 'quotes_historical_yahoo_ohlc' from 'mpl_finance' (c:\\vnstudio\\lib\\site-packages\\mpl_finance.py)"
     ]
    }
   ],
   "source": [
    "\n",
    "# Import required libraries\n",
    "import tushare as ts\n",
    "import matplotlib.pyplot as plt\n",
    "# old version ablish import matplotlib.finance as mpf\n",
    "#from mpl_finance import mpf\n",
    "from mpl_finance import candlestick_ohlc,quotes_historical_yahoo_ohlc\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "8fe56a25",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'quotes_historical_yahoo_ohlc' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_9592/1593714293.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[0mdate2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m2016\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m12\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m  \u001b[1;31m# End date, format: (year, month, day) tuple\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m \u001b[1;31m# Get the stock market history of stock code 601558 from Yahoo Finance\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0mquotes\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mquotes_historical_yahoo_ohlc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'601558.ss'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdate1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdate2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      8\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      9\u001b[0m \u001b[1;31m# Create a subgraph\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'quotes_historical_yahoo_ohlc' is not defined"
     ]
    }
   ],
   "source": [
    "# %matplotlib inline\n",
    "\n",
    "# Set the historical data interval\n",
    "date1 = (2014, 12, 1)  # Starting date, format: (year, month, day) tuple\n",
    "date2 = (2016, 12, 1)  # End date, format: (year, month, day) tuple\n",
    "# Get the stock market history of stock code 601558 from Yahoo Finance\n",
    "quotes = quotes_historical_yahoo_ohlc('601558.ss', date1, date2)\n",
    "\n",
    "# Create a subgraph\n",
    "fig, ax = plt.subplots(facecolor=(0.5, 0.5, 0.5))\n",
    "fig.subplots_adjust(bottom=0.2)\n",
    "# Set the X axis scale to date and time\n",
    "ax.xaxis_date()\n",
    "# X-axis scale text tilted 45 degrees\n",
    "plt.xticks(rotation=45)\n",
    "plt.title(\"Stock code: 601558 two-year chart\")\n",
    "plt.xlabel(\"Time\")\n",
    "plt.ylabel(\"Stock price (yuan)\")\n",
    "candlestick_ohlc(ax, quotes, width=1.2, colorup='r', colordown='green')\n",
    "plt.grid(True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "be36f7cf",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
